<template>
	<el-container>
		<el-container>
			<el-header>
            <div class="left-panel">
                <div class="right-panel-search">
                    <div class="search-input">工厂</div>
                    <el-select v-model="search.supplier_id"  filterable placeholder="请选择工厂" clearable>
                        <el-option v-for="item in gongList" :key="item.apply_id" :label="item.apply_name" :value="item.apply_id"/>
                    </el-select>
                    <div class="search-input">客户</div>
                    <el-select v-model="search.custom_id"  filterable placeholder="请选择客户" clearable>
                        <el-option v-for="item in keHuList" :key="item.custom_id" :label="item.apply_name" :value="item.custom_id"/>
                    </el-select>
                    <div class="search-input">版单编号</div>
                    <el-input v-model="search.order_no" placeholder="请输入版单编号" clearable @change="handleKeyDown" />
                    <div class="search-input">客户款号</div>
                    <el-input v-model="search.factory_art_no" placeholder="请输入客户款号" clearable @change="handleKeyDown" />
                    <el-select v-model="search.status" placeholder="状态" clearable>
                        <el-option label="未审核" :value="0"/>
                        <el-option label="已审核" :value="1"/>
                    </el-select>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                </div>
            </div>
        </el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter border :params="query">
                    <el-table-column type="selection" width="50"></el-table-column>
                    <el-table-column label="版单编号" prop="order_no" align="center" width="150"></el-table-column>
                    <el-table-column label="商品信息" prop="goods" align="center" width="300">
                        <template #default="scope">
                            <div class="shopInfo">
                                <el-image class="img" :src="scope.row.template.images[0]" :preview-src-list="scope.row.template.images" :initial-index="0" fit="cover" preview-teleported="true" hide-on-click-modal />
                                <div class="right">
                                    <div>工厂货号：{{scope.row.template.goods.factory_art_no}}</div>
                                    <div>样衣尺码：{{scope.row.template.goods.size}}</div>
                                    <div>SKC：{{scope.row.template.goods.skc}}</div>
                                    <div>颜色：{{scope.row.template.goods.colour}}</div>
                                    <div v-if="scope.row.template.goods">商品品牌：{{scope.row.template.goods.brand_name}}</div>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="版次" prop="num" align="center" width="150">
                        <template #default="scope">
                            <div>{{scope.row.template.num}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column label="工厂" prop="referred_as" align="center">
                        <template #default="scope">
                            <div>{{scope.row.template.referred_as}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column label="报工人" prop="creator_name" align="center"></el-table-column>
                    <el-table-column label="报工员工" prop="staff_name" align="center"></el-table-column>
                    <el-table-column label="报工工序" prop="process_title" align="center">
                        <template #default="scope">
                            <el-popover placement="top-start" :width="200" trigger="hover" :content="scope.row.process_title" >
                                <template #reference>
                                    <el-button style="padding: 5px 0;" text class="m-2">{{scope.row.process_title.substring(0, 10)}}</el-button>
                                </template>
                            </el-popover>
                        </template>
                    </el-table-column>
                    <el-table-column label="报工次数" prop="many_times" align="center"></el-table-column>
                    <el-table-column label="报工时间" prop="date" align="center"></el-table-column>
                    <el-table-column label="版单状态" prop="audit_status" align="center">
                        <template #default="scope">
                            <el-tag v-if="scope.row.audit_status==0" type="info">待审核</el-tag>
                            <el-tag v-if="scope.row.audit_status==1" type="success">审核通过</el-tag>
                            <el-tag v-if="scope.row.audit_status==2" type="danger">审核驳回</el-tag>
                        </template>
                    </el-table-column>
					<el-table-column label="操作" fixed="right" align="center" width="100">
                        <template #default="scope">
                            <el-button-group style="display:flex;flex-direction:column">
                                <el-button text type="primary" size="small" @click="examine(scope.row, scope.$index)" v-auth="'examine.examine'">审核</el-button>
                                <el-button text type="primary" size="small" @click="exportReport(scope.row, scope.$index)" v-auth="'examine.export'">导出报表</el-button>
                            </el-button-group>
                        </template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
    <examine-save v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false" draggable></examine-save>
</template>

<script>
import examineSave from './examineSave.vue';
export default {
  components: { examineSave },
	name: 'user',
	data() {
		return {
			dialog: {
				save: false,
			},
			group: [],
			apiObj: this.$API.develop.edition.reportList,
			selection: [],
			search: {
				title: null,
				cid: null,
                status:0
			},
            query:{
                status:0
            },
			gongList: [],//供应商
			keHuList: [],//客户
		}
	},
	mounted() {
        this.getGong()
        this.getKehu()
	},
	methods: {
        examine(row) {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("edit").setData(row);
			});
		},
        // 导出报表
        exportReport(row){
            console.log('row :>> ', row);
        },
        // 取消
        async table_cancel(row, index) {
			var reqData = { id: row.id };
			var res = await this.$API.develop.edition.cancel.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
				this.$message.success("取消成功");
			} else {
				this.$alert(res.message, "提示", { type: "error" });
			}
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        handleSuccess(data, mode) {
			if (mode == 'over') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
		},
        // 获取工厂
        async getGong(){
            var res = await this.$API.all.Apply.get();
            this.gongList = res.data;
        },
        // 获取客户
        async getKehu(){
            var res = await this.$API.all.customer.get();
            this.keHuList = res.data;
        },
        handleKeyDown() {
            this.upsearch()
        },
	}
}
</script>

<style lang="scss">
.search-input {
	width: auto;
	font-size: 14px;
}
</style>
